home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
APDL Eductation Resources
/
APDL Eductation Resources.iso
/
programs
/
electronic
/
rlab
/
!RLaB
/
examples
/
matrix_pow
< prev
next >
Encoding:
Amiga
Atari
Commodore
DOS
FM Towns/JPY
Macintosh
Macintosh JP
NeXTSTEP
RISC OS/Acorn
UTF-8
Wrap
Text File
|
1994-02-21
|
358 b
|
24 lines
//
// A simple examples of computing
// A^p, where A is a matrix, and p
// is an integer power.
//
pow = function (a, p)
{
local (mtmp1, mtmp2);
if (p > 4)
{
mtmp1 = a*a;
for (i in 1:(p/2 - 2))
{
mtmp2 = mtmp1*a;
mtmp1 = mtmp2;
}
mtmp1 = mtmp1*mtmp1;
if (mod(p,2) != 0) { mtmp1 = mtmp1*a; }
}
return mtmp1;
};